package com.sanchezsolutions.swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.print.attribute.standard.OrientationRequested;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;

public class MainLayout extends JFrame {

	JPanel pnlCenter;

	public MainLayout() {
		initGUI();
		setTitle("SRCE - Sistema de Registro de Cursos y Estudiantes");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(800, 600);
		setVisible(true);
		setResizable(false);
	}

	private void initGUI() {
		getContentPane().setLayout(new BorderLayout());
		loadMenus();
		loadToolBar();

		pnlCenter = new Welcome();
		add(pnlCenter, BorderLayout.CENTER);

	}

	private void loadToolBar() {
		JToolBar toolBar = new JToolBar();
		toolBar.setFloatable(false);
		toolBar.setOrientation(JToolBar.VERTICAL);

		JButton btnRegisterCourse = new JButton(new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/new_icon.png")));
		btnRegisterCourse.setToolTipText("Registar Curso");
		btnRegisterCourse.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				registerCourseAction();
			}
		});
		toolBar.add(btnRegisterCourse);
		
		JButton btnPrograming = new JButton(new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/new_icon.png")));
		btnPrograming.setToolTipText("Programar Curso");
		toolBar.add(btnPrograming);
		
		JButton btnStatus = new JButton(new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/status_icon.png")));
		btnStatus.setToolTipText("Status de un Curso");
		toolBar.add(btnStatus);
		
		

		getContentPane().add(toolBar, BorderLayout.WEST);

	}

	private void loadMenus() {
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu menu = new JMenu("Archivo");
		menuBar.add(menu);

		JMenuItem menuItem = new JMenuItem("Salir");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
				ActionEvent.CTRL_MASK));
		menuItem.setMnemonic(KeyEvent.VK_S);
		menu.add(menuItem);

		menu = new JMenu("Curso");
		menuBar.add(menu);

		menuItem = new JMenuItem("Registrar", new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/new_icon.png")));
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
				ActionEvent.SHIFT_MASK));
		menuItem.setMnemonic(KeyEvent.VK_R);
		menuItem.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				registerCourseAction();
			}
		});
		menu.add(menuItem);

		menuItem = new JMenuItem("Programar", new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/new_icon.png")));
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,
				ActionEvent.SHIFT_MASK));
		menuItem.setMnemonic(KeyEvent.VK_P);
		menu.add(menuItem);

		menuItem = new JMenuItem("Estatus", new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/status_icon.png")));
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
				ActionEvent.SHIFT_MASK));
		menuItem.setMnemonic(KeyEvent.VK_S);
		menu.add(menuItem);

		menuItem = new JMenuItem("Finalizar", new ImageIcon(getClass()
				.getResource("/com/sanchezsolutions/recursos/status_icon.png")));
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
				ActionEvent.SHIFT_MASK));
		menuItem.setMnemonic(KeyEvent.VK_C);
		menu.add(menuItem);

		menu = new JMenu("Persona");
		menuBar.add(menu);

		menu = new JMenu("Ayuda");
		menuBar.add(menu);

		menuItem = new JMenuItem("Acerca de");
		menu.add(menuItem);

	}

	protected void registerCourseAction() {
		JPanel pnl = (JPanel) getContentPane();
		pnl.remove(pnlCenter);
		pnl.revalidate();
		pnlCenter = new RegisterCourse();
		add(pnlCenter, BorderLayout.CENTER);
		pnl.revalidate();
		pnl.repaint();

	}

	public static void main(String[] args) {
		new MainLayout();
	}

}